"use strict";
cc._RF.push(module, 'cd2c75fb--ca8-6-4c-48-9-343-27b890e9cffd', 'GbzTarget');
// scripts/game/GbzTarget.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var GbzResManager_1 = require("../manager/GbzResManager");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var GbzTarget = /** @class */ (function (_super) {
    __extends(GbzTarget, _super);
    function GbzTarget() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.screwNumMax = 5;
        _this.screwArr = [0, 0, 0, 0, 0, 0, 0];
        return _this;
    }
    GbzTarget.prototype.isActive = function () {
        var active = false;
        for (var i = 0; i < this.screwNumMax; i++) {
            if (!this.screwArr[i]) {
                active = true;
                break;
            }
        }
        return active;
    };
    GbzTarget.prototype.addScrew = function (index, targetScrew) {
        targetScrew.scale = 1;
        targetScrew.getComponent(cc.Sprite).spriteFrame = GbzResManager_1.default.ins.sprite("gbz_screw" + index);
        targetScrew.active = true;
    };
    GbzTarget.prototype.clearAll = function () {
        this.screwArr = [0, 0, 0, 0, 0, 0, 0];
        for (var i = 0; i < this.node.children.length; i++) {
            var target = this.node.children[i];
            var screw = target.getChildByName('screw');
            screw.active = false;
        }
    };
    GbzTarget.prototype.clearOne = function (targetScrew) {
        var i = this.node.children.findIndex(function (target) { return (target.getChildByName('screw')) == targetScrew; });
        this.screwArr[i] = 0;
        targetScrew.active = false;
    };
    GbzTarget.prototype.getLock = function () {
        var targetLock = null;
        for (var i = 0; i < this.node.children.length; i++) {
            var target = this.node.children[i];
            if (target.getChildByName('lock')) {
                targetLock = target.getChildByName('lock');
                break;
            }
        }
        return targetLock;
    };
    GbzTarget.prototype.pushScrew = function (index) {
        for (var i = 0; i < this.screwNumMax; i++) {
            if (!this.screwArr[i]) {
                this.screwArr[i] = index;
                break;
            }
        }
    };
    GbzTarget.prototype.hasScrew = function () {
        var screws = this.getScrews();
        return screws.length;
    };
    GbzTarget.prototype.getScrews = function () {
        var screwArr = [];
        for (var i = 0; i < this.screwNumMax; i++) {
            var target = this.node.children[i];
            var screw = target.getChildByName('screw');
            if (screw.active)
                screwArr.push(screw);
        }
        return screwArr;
    };
    GbzTarget.prototype.getScrewsReal = function () {
        var screwArr = [];
        for (var i = 0; i < this.screwNumMax; i++) {
            if (this.screwArr[i]) {
                var target = this.node.children[i];
                var screw = target.getChildByName('screw');
                screwArr.push(screw);
            }
        }
        return screwArr;
    };
    GbzTarget.prototype.addUnlockNum = function () {
        this.screwNumMax += 1;
    };
    GbzTarget.prototype.getScrewCurrent = function () {
        var targetScrew = null;
        var index = this.screwArr.findIndex(function (screw) { return !screw; });
        if (index >= 0) {
            var target = this.node.children[index];
            var screw = target.getChildByName('screw');
            targetScrew = screw;
        }
        return targetScrew;
    };
    GbzTarget.prototype.checkFull = function () {
        var isFull = true;
        for (var i = 0; i < this.screwNumMax; i++) {
            if (!this.screwArr[i]) {
                isFull = false;
                break;
            }
        }
        if (isFull) {
            for (var i = 0; i < this.screwNumMax; i++) {
                var target = this.node.children[i];
                var screw = target.getChildByName('screw');
                if (!screw.active) {
                    isFull = false;
                    break;
                }
            }
        }
        return isFull;
    };
    GbzTarget = __decorate([
        ccclass
    ], GbzTarget);
    return GbzTarget;
}(cc.Component));
exports.default = GbzTarget;

cc._RF.pop();